package org.feiye.studyday27;

public class SaleRunnable implements Runnable {
	// 模拟网站抢票
	private int count = 10;// 记录剩余票数
	private int num = 0;// 记录当前抢到第几张票

	@Override
	public void run() {
		// 循环抢票，当count=0时结束
		while (true) {
			if (count <= 0)
				break;
			// 1、修改数据（剩余票数、抢到第几张票）
			count--;
			num++;
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		// 2、显示信息,抢到第几张票
		System.out.println(Thread.currentThread().getName() + "抢到了第" + num + "张票！，还剩下" + count + "张票");
	}

	public static void main(String[] args) {
		SaleRunnable sale = new SaleRunnable();

	}
}
